﻿"use strict";

import tap from "tap";
import { sha1 } from "../../src/common/sha1.js";

tap.equal("92cfceb39d57d914ed8b14d0e37643de0797ae56", sha1(42));
tap.equal("21d90aad4d34f48f4aad9b5fa3c37c118af16df9", sha1("Value to be hashed"));
tap.equal("d5d4cd07616a542891b7ec2d0257b3a24b69856e", sha1()); // undefined
tap.equal("2be88ca4242c76e8253ac62474851065032d6833", sha1(null));
tap.equal("08a73daac75982601504c4ba956f49e73ee52667", sha1("abcåäö")); // non-ASCII chars
tap.equal("da39a3ee5e6b4b0d3255bfef95601890afd80709", sha1(""));
tap.equal("11f6ad8ec52a2984abaafd7c3b516503785c2072", sha1("x"));

// The message is broken down to 64 byte blocks. Test the region around 64 bytes.

// 54 chars
tap.equal("6d9fbf872b4e22afee77d8c9e95c10ec03bc731d", sha1("012345678901234567890123456789012345678901234567890123"));

// 55 chars
tap.equal("9f3a4ce7f66b1b74c34da2c5d732c39f81e0f8df", sha1("0123456789012345678901234567890123456789012345678901234"));

// 56 chars
tap.equal("0a40b8fbdaafb7c29651618ac15d27e772287130", sha1("01234567890123456789012345678901234567890123456789012345"));

// 57 chars
tap.equal("46cc79601f8c6b81a4180774ce08465987a225a7", sha1("012345678901234567890123456789012345678901234567890123456"));

// 58 chars
tap.equal("b2aac732d817277777547d2f067df99bb1b5c5ee", sha1("0123456789012345678901234567890123456789012345678901234567"));

// 59 chars
tap.equal("beb7f3acc8e5c80ad813fb013406b58b0dc821ee", sha1("01234567890123456789012345678901234567890123456789012345678"));

// 60 chars
tap.equal("f52e3c2732de7bea28f216d877d78dae1aa1ac6a", sha1("012345678901234567890123456789012345678901234567890123456789"));

// 61 chars
tap.equal("2a1fc3a0fb3d5a6aac17068f5e12e3989269d221", sha1("0123456789012345678901234567890123456789012345678901234567890"));

// 62 chars
tap.equal("bfbe32d71cb46704d9e185cb6b1e42e1b0965635", sha1("01234567890123456789012345678901234567890123456789012345678901"));

// 63 chars
tap.equal("984b0f2f6d78c24020f5a79d409f67ab99302891", sha1("012345678901234567890123456789012345678901234567890123456789012"));

// 64 chars
tap.equal("cf0800f7644ace3cb4c3fa33388d3ba0ea3c8b6e", sha1("0123456789012345678901234567890123456789012345678901234567890123"));

// 65 chars
tap.equal("92de3a8444fe6d15268f0ba810aa43bc8b3a4ffe", sha1("01234567890123456789012345678901234567890123456789012345678901234"));

// 66 chars
tap.equal("54af28647b3c9f53d5c20b2b7877062eb69a4675", sha1("012345678901234567890123456789012345678901234567890123456789012345"));

// 130 chars (spans three blocks)
tap.equal("1f548f0569669daed4fee89712d9019e3d276b55", sha1("0123456789012345678901234567890123456789012345678901234567890123012345678901234567890123456789012345678901234567890123456789012345"));
